import json
from pymongo import MongoClient
"""
检查小红书评论内容与笔记ID无法关联
因：笔记内容与评论内容是两个链接。如果先获取到的是评论内容链接，则无法获取到该笔记的
点赞数量等信息
"""

client = MongoClient('127.0.0.1', 27017)
db = client["DouYin"]
pinglun = db["pinglun_lapeu"]
user = db["user_lapeu"]

pl = pinglun.find({"$and":[{"desc": ""}, {"title": ""}]})
dict_data = []
aa = ""
for t in pl:
    if aa != t.get("note_id"):
        aa = t.get("note_id")
        dict_data.append(t.get("note_id"))

for i in dict_data:
    note_id = i
    uu = user.find_one({'note_id': note_id})
    title = uu.get('title')
    desc = uu.get('desc')
    commentTime1 = uu.get('commentTime1')
    liked_count1 = uu.get('liked_count1')
    collected_count1 = uu.get('collected_count1')
    comments_count1 = uu.get('comments_count1')
    type = uu.get('type')
    pinglun.update_many({'note_id': note_id},{'$set':
                                                      {'liked_count1': liked_count1, 'commentTime1': commentTime1,
                                                       'comments_count1': comments_count1, 'type': type, 'desc': desc, 'title': title}})
    print("=======Update=========")